// components/sort-item/sort-item.js
// import baseComponent from '../wux/helpers/baseComponent'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    sortInfo: {
      type: Object,
      value: {}
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    sortTitle: '',
    sortGroup: []
  },

  attached() {
    let that = this
    wx.nextTick(() => {
      that.setData({
        sortTitle: this.data.sortInfo.title,
        sortGroup: [...this.data.sortInfo.detailList]
      })
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 处理选中操作
     * @param {Object} e 事件对象
     */
    handleItemSelect: function (e) {
      var index = e.target.dataset.index
      var that = this
      var tempGroup = that.data.sortGroup
      tempGroup.forEach((value, i) => {
        var sortSel = "sortGroup[" + i + "].selected"
        if (i === index) {
          that.setData({
            [sortSel]: true
          })
        } else {
          that.setData({
            [sortSel]: false
          })
        }
      })
      var myEventDetail = {
        id: that.data.sortGroup[index].id,
        txt: that.data.sortGroup[index].value,
        picUrl: that.data.sortGroup[index].picUrl
      } // 要发布出去的值
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('select', myEventDetail, myEventOption)
    }
  }
})
